package com.sgcc.ln.pmos.e_ln_mall.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.ln.pmos.arouter.mall.MallArouterPath;
import com.sgcc.ln.pmos.common.bean.ComparisonDetailTopBean;
import com.sgcc.pmos.nativesdk.R;

public class ComparisonDetailTopAdapter extends BaseQuickAdapter<ComparisonDetailTopBean, BaseViewHolder> {

    private int width;

    public ComparisonDetailTopAdapter() {
        super(R.layout.item_comparison_detail_top);

    }

    public void setItemWidth(int width) {
        this.width = width;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ComparisonDetailTopBean s) {
        if (width > 0) {
            ConstraintLayout cl_comparisonDetailTop_itemLayout = baseViewHolder.getView(R.id.cl_comparisonDetailTop_itemLayout);
            RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) cl_comparisonDetailTop_itemLayout.getLayoutParams();
            layoutParams.width = width;
            cl_comparisonDetailTop_itemLayout.setLayoutParams(layoutParams);
        }
        ImageView img_comparisonDetailTop_img = baseViewHolder.getView(R.id.img_comparisonDetailTop_img);
        Glide.with(getContext()).load(s.getImgUrl()).placeholder(R.mipmap.deft_goods)
                .error(R.mipmap.deft_goods).into(img_comparisonDetailTop_img);
        TextView textView = baseViewHolder.getView(R.id.tv_comparisonDetailTop_title);
        textView.setText(s.getName());
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_PACKAGEDETAILS)
                        .withString("combName", s.getCombCode())
                        .navigation();
            }
        });



    }
}
